package com.verlet.springbootdemo.simple.nettyrpc.client;

import com.verlet.springbootdemo.annotation.IgnoreAuth;
import com.verlet.springbootdemo.common.ServerResponse;
import com.verlet.springbootdemo.simple.nettyrpc.UserService;
import com.verlet.springbootdemo.simple.nettyrpc.client.scan.NettyRpcClientRegistrar;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author verlet
 * @date 2020/4/23
 */
@Slf4j
@RestController
@RequestMapping("/rpc")
public class RpcController {
    @Autowired(required = false)
    UserService userService;

    @IgnoreAuth
    @RequestMapping(value = "/callRpc")
    public ServerResponse<String> callRpcTest() {
        log.info("callRpcTest");
        try {
            return ServerResponse.createBySuccess( userService.callRpc("callRpc execute......"));
        } catch (Exception e) {
            log.error("RPC 调用出错", e);
        }
        return ServerResponse.createByErrorMessage("系统异常。");
    }

    @IgnoreAuth
    @RequestMapping(value = "/callRpc2")
    public ServerResponse<String> callRpcTest2() {
        log.info("callRpcTest2");
        try {
            return ServerResponse.createBySuccess( userService.callRpc("callRpc2 execute......"));
        } catch (Exception e) {
            log.error("RPC 调用出错", e);
        }
        return ServerResponse.createByErrorMessage("系统异常。");
    }
}
